const { defineConfig } = require('@vue/cli-service')
const WebpackAliyunOss = require('webpack-aliyun-oss');

const isProduction = process.env.NODE_ENV === 'production';
console.log(isProduction, "isProduction")
module.exports = defineConfig({
  transpileDependencies: true,
  css: {
    loaderOptions: {
      scss: {
        additionalData: `@import '~@/assets/sass/_variable.scss';`
      }
    }
  },
  publicPath: isProduction ? 'https://entertain.cdn.inwuoo.com/chat-ai/' : './', // 生产环境使用绝对路径
  configureWebpack: config => {
    if (isProduction) {
      config.plugins.push(
          new WebpackAliyunOss({
            accessKeyId: 'LTAI5tGDe4EGNMjius28wpRy',
            accessKeySecret: 'GOaRw5YwCrhDP0oQScXY2rEkfEbMX2',
            region: 'oss-cn-hangzhou',
            bucket: 'inwuoo-entertain',
            dist: "chat-ai",
            from: "./dist/**",
            setOssPath: filePath => {
              // some operations to filePapluginsth
              let index = filePath.lastIndexOf("dist");
              let Path = filePath.substring(index + 4, filePath.length);
              return Path.replace(/\\/g, "/");
            },
            setHeaders: () => {
              return {
                "Cache-Control": "max-age=31536000"
              };
            }
          })
      )
    }
  }
})
